package com.gxa.controller.wgl.diagnosis;


import com.gxa.common.R;
import com.gxa.common.vo.DiagnosisDrugVo;
import com.gxa.entity.SysDiagnosis;
import com.gxa.service.SysDiagnosisService;
import com.gxa.utils.HeaderUtils;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping(value = "/diagnosis/diagnosisManagement")
@RequiresRoles(value = {"超级管理员","院长","主任","秘书","助理"},logical = Logical.OR)
@Api(value = "诊断管理",tags = "诊断管理接口API")
public class DiagnosisController {

    @Autowired
    SysDiagnosisService service;

    /**
     * 查询所有诊断结果
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @return R
     */
    @RequestMapping(value = "/findDiagnosisList",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有诊断信息",notes = "查询所有诊断信息",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R findDiagnosisList(Integer currentPage,Integer pageSize){
        return service.selectAllDiagnosis(currentPage,pageSize);
    }




    /**
     * 根据状态查询诊断消息
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @param status 诊单状态
     * @return  R
     */
    @RequestMapping(value = "/findDiagnosisByStatus",method = RequestMethod.GET)
    @ApiOperation(value = "根据状态查询诊断信息",notes = "根据状态查询诊断信息",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "status",value = "状态",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R findDiagnosisByStatus(Integer currentPage,Integer pageSize,Integer status){
        return service.selectDiagnosisByStatus(status,currentPage,pageSize);
    }

    /**
     * 条件查询诊单
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @param condition 条件
     * @return  R
     */
    @RequestMapping(value = "/findDiagnosisByPatientCondition",method = RequestMethod.GET)
    @ApiOperation(value = "条件查询诊断信息",notes = "条件查询诊断信息",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "condition",value = "条件",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R findDiagnosisByPatientCondition(Integer currentPage,Integer pageSize,String condition){
        return service.findDiagnosisByPatientCondition(condition,currentPage,pageSize);
    }
    /**
     * 添加一条诊断消息
     * @param sysDiagnosis 诊断实体
     * @return  R
     */
    @RequestMapping(value = "/addDiagnosis",method = RequestMethod.POST)
    @ApiOperation(value = "添加一条诊断消息",notes = "添加一条诊断消息",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R addService(@RequestBody @ApiParam(name = "sysDiagnosis",value = "消息实体",required = true) SysDiagnosis sysDiagnosis,
                        HttpServletRequest request){
        Integer userId = HeaderUtils.getUserID(request);
        sysDiagnosis.setUserId(userId);
        return service.addSysDiagnosis(sysDiagnosis);
    }


    /**
     * 在诊断单里面添加药品
     * @param diagnosisDrugVo 诊断药品实体
     * @return  R
     */
    @RequestMapping(value = "/addDiagnosisDrug",method = RequestMethod.POST)
    @ApiOperation(value = "在诊断单里面添加药品",notes = "在诊断单里面添加药品",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R addDiagnosisDrug(@RequestBody @ApiParam(name = "diagnosisDrugVo",value = "消息实体",required = true) DiagnosisDrugVo diagnosisDrugVo){
        return service.addDiagnosisDrug(diagnosisDrugVo);
    }

    /**
     * 根据id回显信息
     * @param id 编号
     * @return R
     */
    @RequestMapping(value = "/findDiagnosisById",method = RequestMethod.GET)
    @ApiOperation(value = "根据id回显信息",notes = "根据id回显信息",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "诊断ID",paramType = "query",dataType = "String",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R findDiagnosisById(Integer id){
        return service.selectDiagnosisById(id);
    }

    /**
     * 修改一条诊断消息
     * @param sysDiagnosis 诊断实体
     * @return  R
     */
    @RequestMapping(value = "/updateDiagnosis",method = RequestMethod.POST)
    @ApiOperation(value = "修改一条诊断消息",notes = "修改一条诊断消息",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R updateDiagnosis(@RequestBody @ApiParam(name = "sysDiagnosis",value = "消息实体",required = true) SysDiagnosis sysDiagnosis){
        return service.updateDiagnosisById(sysDiagnosis);
    }

    /**
     * 删除一条诊断消息
     * @param id 诊断编号
     * @return  R
     */
    @RequestMapping(value = "/deleteDiagnosisById",method = RequestMethod.POST)
    @ApiOperation(value = "删除一条诊断消息",notes = "删除一条诊断消息",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "诊断Id",paramType = "query",dataType = "String",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R deleteDiagnosisById(Integer id){
        return service.delDiagnosisById(id);
    }


    /**
     * 根据诊断编号查询诊断药品信息
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @param diagnosisId 诊断编号
     * @return  R
     */
    @RequestMapping(value = "/findDiagnosisDrugById",method = RequestMethod.GET)
    @ApiOperation(value = "根据诊断ID分页查询诊断药品信息",notes = "根据诊断ID分页查询诊断药品信息",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "diagnosisId",value = "诊断ID",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R findDiagnosisDrugById(Integer currentPage,Integer pageSize,Integer diagnosisId){
        return service.selectDiagnosisDrugById(diagnosisId,currentPage,pageSize);
    }


    /**
     * 根据条件分页查询诊断药品信息
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @param condition 条件
     * @param diagnosisId 诊断ID
     * @return  R
     */
    @RequestMapping(value = "/findDiagDrugByCondition",method = RequestMethod.POST)
    @ApiOperation(value = "根据条件分页查询诊断药品信息",notes = "根据条件分页查询诊断药品信息",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "condition",value = "条件",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "diagnosisId",value = "诊断ID",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R findDiagDrugByCondition(Integer currentPage,Integer pageSize,String condition,Integer diagnosisId){
        return service.findDiagDrugByCondition(currentPage,pageSize,condition,diagnosisId);
    }


    /**
     * 根据诊断编号药品编号回显诊断药品信息
     * @param drugId 药品编号
     * @param id 诊断药品主id
     * @return R
     */
    @RequestMapping(value = "/findDiagnosisDrugByDrug",method = RequestMethod.GET)
    @ApiOperation(value = "根据诊断药品主ID药品ID回显诊断药品信息",notes = "根据诊断药品主ID药品ID回显诊断药品信息",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "drugId",value = "药品ID",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "id",value = "诊断药品主id",paramType = "query",dataType = "String",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R findDiagnosisDrugByDrug(Integer drugId,Integer id){
        return service.findDiagnosisDrugByDrug(drugId,id);
    }


    /**
     * 根据诊断编号药品编号修改诊断药品数量
     * @param id 诊断药品主编号
     * @param num 修改诊断药品数量
     * @return  R
     */
    @RequestMapping(value = "/updateDiagnosisDrug",method = RequestMethod.POST)
    @ApiOperation(value = "根据诊断药品主ID修改诊断药品数量",notes = "根据诊断药品主ID修改诊断药品数量",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "num",value = "修改诊断药品数量",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "id",value = "诊断药品主ID",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "drugId",value = "药品ID",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R updateDiagnosisDrug(Integer num,Integer id,Integer drugId){
        return service.updateDiagnosisDrug(num,id,drugId);
    }


    /**
     * 根据药品编号，诊断编号删除诊断药品信息
     * @param id 诊断药品主ID
     * @return  R
     */
    @RequestMapping(value = "/delDiagnosisDrug",method = RequestMethod.POST)
    @ApiOperation(value = "根据诊断药品主ID删除诊断药品信息",notes = "根据诊断药品主ID删除诊断药品信息",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "诊断药品主ID",paramType = "query",dataType = "String",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R delDiagnosisDrug(Integer id){
        return service.delDiagnosisDrug(id);
    }


    /**
     * 根据类型统计信息
     * @return R
     */
    @RequestMapping(value = "/countDiagnosisByType",method = RequestMethod.GET)
    @ApiOperation(value = "根据类型统计信息",notes = "根据类型统计信息",httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R countDiagnosisByType(){
        return service.countDiagnosisByType();
    }

    /**
     * 统计所有信息
     * @return R
     */
    @RequestMapping(value = "/countDiagnosis",method = RequestMethod.GET)
    @ApiOperation(value = "统计所有信息",notes = "统计所有信息",httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R countDiagnosis(){
        return service.countDiagnosis();
    }


    /**
     * 统计药品所有信息
     * @param type 诊断类型
     * @return R
     */
    @RequestMapping(value = "/countDiagnosisDrugsByType",method = RequestMethod.GET)
    @ApiOperation(value = "统计药品所有信息,type=NULL代表统计全部",notes = "统计药品所有信息,type=NULL代表统计全部",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "诊断类型",paramType = "query",dataType = "String",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R countDiagnosisDrugs(Byte type){
        return service.countDiagnosisDrugs(type);
    }



    /**
     * 统计诊断月分所有信息
     * @param type 诊断类型
     * @return R
     */
    @RequestMapping(value = "/countDiagnosisMonthByType",method = RequestMethod.GET)
    @ApiOperation(value = "统计诊断月分所有信息,type=NULL代表统计全部",notes = "统计诊断月分所有信息,type=NULL代表统计全部",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "诊断类型",paramType = "query",dataType = "String",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R countDiagnosisMonth(Byte type){
        return service.countDiagnosisMonth(type);
    }


    /**
     * 统计诊断每日所有信息
     * @param type 诊断类型
     * @return R
     */
    @RequestMapping(value = "/countDiagnosisMonthDayByType",method = RequestMethod.GET)
    @ApiOperation(value = "统计诊断每日所有信息,type=NULL代表统计全部",notes = "统计诊断每日所有信息,type=NULL代表统计全部",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "诊断类型",paramType = "query",dataType = "String",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R countDiagnosisMonthDay(Byte type){
        return service.countDiagnosisMonthDay(type);
    }

    /**
     * 统计诊断所有条数
     * @return
     */
    @RequestMapping(value = "/countAllDiagnosis",method = RequestMethod.GET)
    @ApiOperation(value = "统计诊断所有条数",notes = "统计诊断所有条数",httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R countAllDiagnosis(){
        return service.countAllDiagnosis();
    }


    /**
     * 统计周诊断所有条数
     * @return
     */
    @RequestMapping(value = "/countWeekDiagnosis",method = RequestMethod.GET)
    @ApiOperation(value = "统计周诊断所有条数",notes = "统计周诊断所有条数",httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R countWeekDiagnosis(){
        return service.countWeekDiagnosis();
    }



}
